package com.it2297.view;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JTextField;

import com.it2297.controller.WorkshopParticipatedController;
import com.it2297.main.UserApp;
import com.it2297.model.WorkshopParticipant;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class WorkshopParticipatedView extends JPanel {
	
	private final WorkshopParticipatedController control=new WorkshopParticipatedController(this);
	private final JTextField participanttxt;
	private final JTextField workshopidtxt;
	private final JTextField titletxt;

	/**
	 * Create the panel.
	 */
	public WorkshopParticipatedView() {
		setLayout(null);
		
		JLabel lblJoinWorkshops = new JLabel("Join Workshops/Unjoin Workshops");
		lblJoinWorkshops.setFont(new Font("Tahoma", Font.ITALIC, 20));
		lblJoinWorkshops.setBounds(27, 11, 394, 37);
		add(lblJoinWorkshops);
		
		JLabel lblWorkshopId = new JLabel("Workshop Id");
		lblWorkshopId.setBounds(27, 144, 92, 14);
		add(lblWorkshopId);
		
		JLabel lblParticipantId = new JLabel("Participant Id");
		lblParticipantId.setBounds(27, 79, 104, 14);
		add(lblParticipantId);
		
		JLabel lblTitle = new JLabel("Title: ");
		lblTitle.setBounds(27, 205, 92, 14);
		add(lblTitle);
		
		JButton btnJoin = new JButton("Join");
		btnJoin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				control.CreateWorkshopParticipatedRecord();
				
			}
		});
		btnJoin.setBounds(59, 284, 89, 23);
		add(btnJoin);
		
		JButton btnRefresh = new JButton("Refresh");
		btnRefresh.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				participanttxt.setText("");
				titletxt.setText("");
				workshopidtxt.setText("");
				
				
			}
		});
		btnRefresh.setBounds(278, 284, 89, 23);
		add(btnRefresh);
		
		participanttxt = new JTextField();
		participanttxt.setBounds(185, 76, 236, 20);
		add(participanttxt);
		participanttxt.setColumns(10);
		
		workshopidtxt = new JTextField();
		workshopidtxt.setBounds(185, 141, 236, 20);
		add(workshopidtxt);
		workshopidtxt.setColumns(10);
		
		titletxt = new JTextField();
		titletxt.setBounds(185, 202, 236, 20);
		add(titletxt);
		titletxt.setColumns(10);
		
		JButton btnUnjoin = new JButton("Unjoin");
		btnUnjoin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				control.UnjoinParticipatedWorkshop();
				
			}
		});
		btnUnjoin.setBounds(179, 284, 89, 23);
		add(btnUnjoin);

	}
	public int getWorkshopId(){
		
		return Integer.parseInt(workshopidtxt.getText());
	}
	
	public String getNRIC(){
		return UserApp.getCurrentUser().getNric();
	}
	public String getTitle(){
		return titletxt.getText();
	}
	public String getName(){
		return UserApp.getCurrentUser().getName();
	}
	public int getParticipantId(){
		return Integer.parseInt(participanttxt.getText());
	}
}
